package com.hulk.boot.config;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.ehcache.EhCacheCacheManager;
import org.springframework.cache.ehcache.EhCacheManagerFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;

/** 
* @author 作者  cmt
* 类说明 
*/

@Configuration
@EnableCaching
public class EhCacheConfig  {
	
	
	 /*
	   * 据shared与否的设置,Spring分别通过CacheManager.create()或new CacheManager()方式来创建一个ehcache基地.
	   */
	  @Bean(name="ehCacheManagerFactoryBean")
	  public EhCacheManagerFactoryBean ehCacheManagerFactoryBean(){
	    EhCacheManagerFactoryBean cacheManagerFactoryBean = new EhCacheManagerFactoryBean ();
	    cacheManagerFactoryBean.setConfigLocation (new ClassPathResource ("config/ehcache.xml"));
	    cacheManagerFactoryBean.setShared (true);
	    cacheManagerFactoryBean.setCacheManagerName("cacheManagerName");
	    return cacheManagerFactoryBean;
	  }
	
	 /*
	   * ehcache 主要的管理器
	   */
	  @Bean(name = "ehCacheCacheManager")
	  //@Qualifier("ehCacheCacheManager")
	  public EhCacheCacheManager ehCacheCacheManager(EhCacheManagerFactoryBean bean){
		  EhCacheCacheManager  ehCacheCacheManager= new EhCacheCacheManager(bean.getObject());
	    return ehCacheCacheManager;
	  }

	 
	  
	  
//	  
//	   <!-- 定义CacheManager -->
//
//	   <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
//
//	      <!-- 指定配置文件的位置 -->
//
//	      <property name="configLocation" value="/WEB-INF/config/ehcache.xml"/>
//
//	      <!-- 指定新建的CacheManager的名称 -->
//
//	      <property name="cacheManagerName" value="cacheManagerName"/>
//
//	   </bean>
//
//	  
//
//	   <!-- 定义一个Ehcache -->
//
//	   <bean id="userCache" class="org.springframework.cache.ehcache.EhCacheFactoryBean">
//
//	      <property name="cacheName" value="user"/>
//
//	      <property name="cacheManager" ref="cacheManager"/>
//
//	   </bean>

}
